//
//  WeathersCollectionViewCell.m
//  WeatherGuide
//
//  Created by lanou3g on 15/12/18.
//  Copyright © 2015年 李明. All rights reserved.
//

#import "WeathersCollectionViewCell.h"

#import "Weather.h"
#import "Aqi.h"
#import "DailyForecast.h"
#import "WeatherForecastView.h"
#import "GetWeatherHandle.h"
#import "WeatherDetailsView.h"
#import "WeatherHomeView.h"
#import "WeatherScrollView.h"
#import "AqiViewController.h"
@interface WeathersCollectionViewCell ()<UIScrollViewDelegate>

{
     CALayer *_layer;
}

@property (nonatomic,copy) NSString *text;

@property (strong, nonatomic) IBOutlet WeatherHomeView *weatherHomeView;
@property (strong, nonatomic) IBOutlet UIImageView *backImageView;

@end

@implementation WeathersCollectionViewCell

- (void)awakeFromNib {
    self.qltyButton.layer.cornerRadius = 5;
    
    self.weatherHomeView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)];
    [self.weatherHomeView addGestureRecognizer:tapGR];

    self.weatherScrollView.delegate = self;
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _layer = [CALayer layer];
    self.backImageView.alpha = 1.0 - scrollView.contentOffset.y / 2 / scrollView.contentSize.height;
    
    
//    [self.backgroundView.layer addSublayer:_layer];
    
// 
//    NSLog(@"%f",self.backImageView.alpha);
//    NSLog(@"%f",scrollView.contentOffset.y);
//    NSLog(@"%f",scrollView.contentSize.height);
//    
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
  
  
}

- (void)tapGRAction:(UITapGestureRecognizer *)sender{
    self.weatherScrollView.contentOffset = CGPointMake(0, self.weatherHomeView.bounds.size.height);
    
}




- (void)setWeather:(Weather *)weather
{
    NSLog(@"weather -----aqi%@",weather.txt);
    if (weather.aqi.pm10.length) {
        self.PM10Label.text = weather.aqi.aqi;
    }
    if (weather.aqi.qlty.length) {
        [self.qltyButton setTitle:weather.aqi.qlty forState:UIControlStateNormal];
        if ([weather.aqi.qlty isEqualToString:@"优"]) {
            self.qltyButton.backgroundColor = [UIColor greenColor];
        }else if ([weather.aqi.qlty isEqualToString:@"良"]){
            self.qltyButton.backgroundColor = [UIColor blueColor];
        }else if ([weather.aqi.qlty isEqualToString:@"轻度污染"]){
            self.qltyButton.backgroundColor = [UIColor purpleColor];
        }else if ([weather.aqi.qlty isEqualToString:@"中度污染"]){
            self.qltyButton.backgroundColor = [UIColor orangeColor];
        }else if ([weather.aqi.qlty isEqualToString:@"重度污染"]){
            self.qltyButton.backgroundColor = [UIColor redColor];
        }else if ([weather.aqi.qlty isEqualToString:@"严重污染"]){
            self.qltyButton.backgroundColor = [UIColor magentaColor];
        }
    }
    self.minTmpLabel.text = weather.dailyForecast1.min;
    self.maxTmpLabel.text = weather.dailyForecast1.max;
    [self.cityButton setTitle:weather.city forState:UIControlStateNormal];
    self.condLabel.text = weather.txt;
    
    NSLog(@"%@",weather.txt);
    self.weatherDetailsView.weather = weather;
    
    self.tmpLabel.text = self.weatherDetailsView.tmp;
    self.dateLabel.text = [NSString stringWithFormat:@"%@更新",self.weatherDetailsView.date];
    
    self.condImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",weather.dailyForecast1.code_d]];
    
    self.weatherForecast1.dailyForecast = weather.dailyForecast1;
    self.weatherForecast2.dailyForecast = weather.dailyForecast2;
    self.weatherForecast3.dailyForecast = weather.dailyForecast3;
    self.weatherForecast4.dailyForecast = weather.dailyForecast4;
    self.weatherForecast5.dailyForecast = weather.dailyForecast5;
    self.weatherForecast6.dailyForecast = weather.dailyForecast6;
    self.weatherForecast7.dailyForecast = weather.dailyForecast7;
    
    
    [GetWeatherHandle sharedHandle].arrayLifeIndexLevel = @[weather.comf,weather.cw,weather.drsg,weather.flu,weather.sport,weather.trav,weather.uv];
    
    
}


@end
